import json
import os
import sys
import redis
from checker import *

path = 'D:\\PaperWork\\Stage2\\gt\\'
sep = os.path.sep
consumer_pool = redis.ConnectionPool(host="192.168.3.70", port=6379, db=1)
producer_pool = redis.ConnectionPool(host="192.168.3.70", port=6379, db=2)

consumer = redis.Redis(connection_pool=consumer_pool)
producer = redis.Redis(connection_pool=producer_pool)

if not os.path.exists(path + "out"):
    os.mkdir(path + "out")

res_consumer = consumer.lrange('apk_name', 0, -1)
count = 0
for app in res_consumer:
    if producer.get(app) is not None:
        print "Result exists,continue!"
        continue
    dir = path + app + sep
    if not os.path.exists(dir):
        print "directory or file:" + dir + "not exists, continue..."
        continue
    # print(dir)
    result = check(dir)
    count += 1
    if (result == False):
        producer.set(app, json.dumps(result))
        continue
        # print result
        # producer.set(app, json.dumps(result))
print count
